package com.gitee.cashzhang27.test.boot.functional.biz;

import com.gitee.cashzhang27.test.boot.functional.entity.Person;
import com.gitee.cashzhang27.test.boot.functional.service.PersonService;
import java.util.List;
import javax.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * @author Cash Zhang
 * @version v1.0 2020/09/16 15:48
 * @since v1.0
 */
@Service
@Validated
@AllArgsConstructor
public class PersonBiz {

  private PersonService personService;

  public List<Person> listPeople() {
    return this.personService.list();
  }

  @CachePut(cacheNames = "person", key = "#result.id")
  public Person createPerson(@Valid Person person) {
    this.personService.save(person);
    return person;
  }

  public void createPersons(List<Person> people) {
    this.personService.saveBatch(people);
  }

  @Cacheable(cacheNames = "person", key = "#personId")
  public Person getPerson(String personId) {
    return this.personService.getById(personId);
  }

}
